﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;

public partial class user_favimg_albums : System.Web.UI.Page
{
    //store old : a_album_sel
    //table : a_Albums
    public bool edit = false;
    public a_Album album;
    public a_AlbumCollection albums;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!SessionManager.IsLogged)
            Response.Redirect("login.aspx?ckid=" + SessionManager.GetCookie(), true);
        if (IsPostBack)
        {
            //Page.Title = Request["act"] + " - " + Request["ten_album"];
            try
            {
                if (Request["act"] == "add")
                {
                    a_User usr = a_UserService.Geta_UserBySSID(SessionManager.GetCookie());
                    a_Album ab = new a_Album();
                    ab.Name = Request["Name"];
                    ab.AlbumType = bool.Parse(Request["AlbumType"]);
                    ab.UserID = usr.UserID;
                    ab.StatPopularity = 0;
                    a_AlbumService.Createa_Album(ab);
                }
                else if (Request["act"] == "update")
                {
                    a_Album ab = a_AlbumService.Geta_Album(int.Parse(Request["idAb"]));
                    ab.Name = Request["Name"];
                    ab.AlbumType = bool.Parse(Request["AlbumType"]);
                    a_AlbumService.Updatea_Album(ab);
                    InfoText.InnerHtml = "Đã cập nhật thành công";
                }
                
                InfoText.Visible = true;
            }
            catch (Exception ex)
            {
                Page.Title = ex.Message;
            }
        }
        else
        {
            Form.Attributes.Add("onsubmit", "return CheckFavImg(this);");
            Form.Method = "post";
            
        }
        if (Request["act"] == "del")
        {
            a_AlbumService.Deletea_Album(int.Parse(Request["AlbumID"]));
            InfoText.InnerHtml = "Đã xóa album";
            InfoText.Visible = true;
        }
        if (Request["AlbumID"] != null && Request["act"] != "del")
        {
            album = a_AlbumService.Geta_Album(int.Parse(Request["AlbumID"]));
            edit = true;
        }
        albums = a_AlbumService.Geta_AlbumListBySSID(SessionManager.GetCookie(), a_AlbumColumns.Name, ThoiTrang.Data.OrderDirection.ASC);
    }
}
